import simplejson as json

class Item():
	"""Simple Item Object"""
	
	def __init__(self, request):
		#User the request Object to populate the item
		self.request = None
		self.request=request
		self._parseRequest()
	
	def info(self):
		return self.data.keys()
		
	def _parseRequest(self):
		#convert the wowhead 'json' into json
		self.data = self.request
		self.data.update( json.loads( self._toJson( self.request["json"] ) ) )
		self.data.update( json.loads( self._toJson( self.request["jsonEquip"] ) ) )
		
		#The name has the item quality as first character
		#0 account bind
		#1 artifact
		#2 legendary
		#3 epic
		#4 blue
		#5 green
		#6 white
		#The quality can be readed fron 'quality' or 'quality_id' , so we remove it.
		self.data["name"] = self.data["name"][1:]
	
	def _toJson(self,data):
		return '{"'+data.replace("'",'"').replace(":",'":').replace(",",',"').replace("{",'{"')+"}"
		
	def __getattr__(self, key):
		try:
			return self.data[key]
		except:
			return None
			
	def __str__(self):
		return "["+str(self.id)+" : "+self.name+"]"
	